/**
*  \file candispatcher.h
*
*  \brief
*
*  \author Michael J. Hohmann  michael.hohmann@linde-mh.de
*
*
*
*
*
*/
#ifndef CANDISPATCHER_H_INCLUDED
#define CANDISPATCHER_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../canmsg/canmsg.h"

/*================================================[ public defines   ]================================================*/

/** Number of possible IDs */
#define CANDISPATCHER_ID_TABLE_SIZE  U16_CONST(0x800)

/*================================================[ public datatypes ]================================================*/
struct candispatcher_obj;/* forward declaration */

/** Callback function Type */
typedef void (*candispatcher_callback_function_t)(struct canmsg* msg, void * data );

struct candispatcher_entry
{
	canmsg_id_t id;
	candispatcher_callback_function_t callback;
	void * callback_data;
};

/** Object definition.
* 
* The struct candispatcher_obj defines the attribute of an object.
*/
struct candispatcher_obj
{	
   //candispatcher_callback_function_t dispatch_table[CANDISPATCHER_ID_TABLE_SIZE];   /**< Store callback function for all IDs      */
   candispatcher_callback_function_t default_callback;
   pal_size_t table_size;
   pal_size_t current_size;
   struct candispatcher_entry * table;
   void * forward_data;
   BO enable;};

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/

/**
*  Constructor.
*
*  Construct an object. 
*
*  \param me Object pointer. NULL will throw an assert.
*
*  \return RC_SUCCESS if successful.
*/
RC candispatcher_construct( struct candispatcher_obj* me ,struct candispatcher_entry *table, pal_size_t table_size );

void candispatcher_install_default_callback( struct candispatcher_obj* me, candispatcher_callback_function_t callback );
void candispatcher_install_callback( struct candispatcher_obj* me, canmsg_id_t id, candispatcher_callback_function_t callback, void* callback_data );

RC candispatcher_enable(struct candispatcher_obj* me, BO value);
void candispatcher_dispatch_message(struct candispatcher_obj *me, struct canmsg *msg);

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2018 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
